const {Sequelize,DataTypes}=require('sequelize')
const fs=require('fs')
const user=require('./User')

let sequelize=new Sequelize('softone','postgres','dhb123...',{
    host:'lifesunny.top',
    dialect:'postgres'
})

let file=fs.readdirSync(__dirname)
let files=file.filter(item=>{
    return item.endsWith('.js') && item!='index.js'
})

let resObj={}
files.filter(item=>{
    let modelName=item.replace('.js','')
    let tabName=modelName.toLowerCase()
    let temObj=require(__dirname+'/'+item)
    resObj[modelName]=sequelize.define(tabName,temObj)
})
console.log(resObj);
resObj.sync=async()=>{
    sequelize.sync({force:true}).then(data=>{
        resObj.User.bulkCreate([
            {
                biaoti:'论EF Core的自我修养',
                zhaiyao:'论EF Core的自我修养',
                neirong:'论EF Core的自我修养',
                fenlei:'.NET',
                zuozhe:'InCerry'
            },
            {
                biaoti:'DDD之我见',
                zhaiyao:'DDD之我见',
                neirong:'DDD之我见',
                fenlei:'编程技术',
                zuozhe:'某大神'
            },
            {
                biaoti:'nginx负载平衡的集中测略',
                zhaiyao:'nginx负载平衡的集中测略',
                neirong:'nginx负载平衡的集中测略',
                fenlei:'服务器',
                zuozhe:'老虎腊鱼'
            },
            {
                biaoti:'Linux用户创建的学习研究',
                zhaiyao:'Linux用户创建的学习研究',
                neirong:'Linux用户创建的学习研究',
                fenlei:'Linux',
                zuozhe:'某大神'
            },
            {
                biaoti:'大数据仪表盘',
                zhaiyao:'大数据仪表盘',
                neirong:'大数据仪表盘',
                fenlei:'居家博士',
                zuozhe:'InCerry'
            },
        ])
    })
}
module.exports=resObj